package com.nf.health.app.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.nf.health.app.R;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Jason on 2016/3/31.
 */
public class ItemHealthStateAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private List<String> titles = new ArrayList<>();
    private List<String> contents = new ArrayList<>();

    public ItemHealthStateAdapter(Map<String, List<String>> mDatas) {
        for(Map.Entry<String, List<String>> item : mDatas.entrySet()){
            titles.add(item.getKey());
            StringBuilder sb = new StringBuilder();
            for(int i = 0;i<item.getValue().size();i++){
                sb.append((i+1)+".");
                sb.append(item.getValue().get(i));
                if(i!=item.getValue().size()-1){
                    sb.append("\r\n");
                }
            }
            contents.add(sb.toString());
        }
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_health_state_child1, parent, false);
        return new ItemChildViewHolder(itemView);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        ((ItemChildViewHolder)holder).tvTitle.setText(titles.get(position));
        ((ItemChildViewHolder)holder).tvContent.setText(contents.get(position));
    }

    @Override
    public int getItemCount() {
        return titles == null ? 0 : titles.size();
    }

    class ItemChildViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.tv_title)
        TextView tvTitle;
        @Bind(R.id.tv_content)
        TextView tvContent;
        public ItemChildViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
